import 'dart:async';

import 'package:qgchat/http/apis/user.dart';
import 'package:qgchat/http/models/anchorInfoModel.dart';
import 'package:qgchat/http/models/tagModel.dart';

import '../blocProvider.dart';

class AnchorInfoBloc implements BlocBase {

  @override
  void dispose() {
    _anchorInfoController.close();
    _tagController.close();
  }



// STREAMS======================================================================

  /// 主播信息stream
  StreamController<AnchorInfoModel> _anchorInfoController = StreamController.broadcast();
  Sink<AnchorInfoModel> get _fansSink => _anchorInfoController.sink;
  Stream<AnchorInfoModel> get outAnchorInfoStream => _anchorInfoController.stream;

  /// tagStream
  StreamController<TagModel> _tagController = StreamController();
  Sink<TagModel> get _tagSink => _tagController.sink;
  Stream<TagModel> get outTagStream => _tagController.stream;

// HANDLING=====================================================================

  /// 获取主播信息
  void getAnchorInfo(String memberToken) async {
    AnchorInfoModel result = await UserApis.getAnchorInfo(memberToken);
    _fansSink.add(result);
  }

  /// 获取tag
  void getTag(String tagId) async {
    TagModel tagName;
    List<TagModel> result = await UserApis.getTag();
    for (TagModel item in result) {
      if (item.id.toString() == tagId) {
        tagName = item;
      }
    }
    _tagSink.add(tagName);
  }

}